package pl.javarsovia.javarsovia4android.xml;

import org.w3c.dom.Element;
import pl.javarsovia.javarsovia4android.domain.*;
import pl.javarsovia.javarsovia4android.tmp.DummyPartnersParser;
import pl.javarsovia.javarsovia4android.util.XMLUtils;
import pl.javarsovia.javarsovia4android.xml.parsers.*;

import java.io.InputStream;
import java.util.List;

/**
 * @author mgrzechocinski
 * @since 2010-06-12
 */
public class ConferenceParser {

	// Parsers
	LecturesParser lecturesParser = new LecturesParser();
	SpeakersParser speakersParser = new SpeakersParser();
	RoomsParser roomsParser = new RoomsParser();
	SlotsParser slotsParser = new SlotsParser();
	PartnersParser partnersParser = new DummyPartnersParser();

	private final InputStream inputStream;

	public ConferenceParser(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public Conference unmarshall() {
		Element root = getRootElement();
		List<Slot> slots = slotsParser.unmarshallAll(root);
		List<Speaker> speakers = speakersParser.unmarshallAll(root);
		List<Room> rooms = roomsParser.unmarshallAll(root);
		List<Partner> partners = partnersParser.unmarshallAll(root);

		lecturesParser.unmarshallAll(root, speakers, slots, rooms);

		return new Conference().rooms(rooms).partners(partners).slots(slots);

	}

	Element getRootElement() {
		return XMLUtils.getRoot(inputStream);
	}

}
